<?php

    /**
    * Manage ABSoft Banners items
    * 
    * @author: trungdt
    * @since Apr 2, 2011
    * @version 1.0
    */

    if (!defined('EXPONENT')) exit('');

    global $db;

    $config = $db->selectObject('abbannermodule_config',"location_data='".serialize($loc)."'");
    if ($config == null) {
        $template = new template('abbannermodule','notconfigured',$loc);
        $template->output();
    }
    else
    {
        if (exponent_permissions_check("administrate", $loc) || exponent_permissions_check("create", $loc) || exponent_permissions_check("create", $loc) || exponent_permissions_check("edit", $loc) || exponent_permissions_check("delete", $loc))
        {
            $items = $db->selectObjects('abbanner',"location_data='".serialize($loc)."' ORDER BY show_type, rank");
            foreach ($items as $key=>$value){
                // check file id
                if ($value->show_type == 1)
                {
                    $file = $db->selectObject('file', 'id='.$value->img_fileid);
                    $value->img_path= "/".$file->directory.'/'.$file->filename;
                }
                else if ($value->show_type == 2){
                    $file = $db->selectObject('file', 'id='.$value->flash_fileid);
                    $value->flash_path= "/".$file->directory.'/'.$file->filename;
                }
            }
            $template = new template('abbannermodule','_manage',$loc);
            $template->assign('items',$items);
            $template->assign('config',$config);
            $template->register_permissions(
            array('administrate','configure','create','edit','delete'),$loc);
            // set flow
            exponent_flow_set(SYS_FLOW_PROTECTED,SYS_FLOW_ACTION);
            $template->output();
            exponent_sessions_set("AB_THEME_TOP_CONTAINER_SRC","top_loginmodule_".LANG);
    exponent_sessions_set("AB_THEME_TOP_CONTAINER_TYPE","textmodule");
        }
        else
        {
            exponent_http_error(403);
        }
    }

?>